package com.ruoyi.user.controller;

import com.ruoyi.common.core.cg.dto.QueryOrderDto;
import com.ruoyi.common.core.cg.pojo.Order;
import com.ruoyi.common.core.cg.result.OrderDetailResult;
import com.ruoyi.common.core.cg.result.PageResult;
import com.ruoyi.common.core.cg.result.Result;
import com.ruoyi.user.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService service;
    @RequestMapping("findOrderById")
    public Result findOrderById(Integer orderId,Integer userId){
        try {
            OrderDetailResult orderDetailResult = service.findOrderById(orderId,userId);
            return new Result(true,"查询订单成功",orderDetailResult);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询订单失败");
        }
    }

    /**
     * 通过订单状态查询用户
     * @param queryOrderDto
     * @return
     */
    @RequestMapping("findOrderByState")
    public PageResult findUserOrderByState(@RequestBody QueryOrderDto queryOrderDto){
        try {
            return service.findUserOrderByState(queryOrderDto);
        }catch (Exception e){
            e.printStackTrace();
            return new PageResult(0L,null);
        }
    }

}
